﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BanVeXemPhim_Presentation
{
    public partial class UserControlChonLichChieu : UserControl
    {
        public UserControlChonLichChieu()
        {
            InitializeComponent();
        }

        public delegate void Back();
        public event Back BackClickEvent;

        public delegate void Next(XuatChieuDTO xuatChieuDto);
        public event Next NextClickEvent;

        public delegate void DatVeOnline(XuatChieuDTO xuatChieuDto);
        public event DatVeOnline XuLyDatVeOnline;

        private XuatChieuDTO[] _danhSachXuatChieu;

        public XuatChieuDTO[] DanhSachXuatChieu
        {
            get { return _danhSachXuatChieu; }
            set
            {
                _danhSachXuatChieu = value;
                if(_danhSachXuatChieu!=null)
                {
                    dataGridView.DataSource = _danhSachXuatChieu;
                    dataGridView.Columns["Gio"].HeaderText = "Giờ chiếu";
                    dataGridView.Columns["IdXuatChieu"].Visible = false;
                    dataGridView.Columns["Phim"].Visible = false;
                    dataGridView.Columns["IdTuan"].Visible = false;
                    dataGridView.Columns["RapChieu"].HeaderText = "Rạp chiếu";
                    dataGridView.Columns["GioChieu"].Visible = false;
                    dataGridView.Columns["NgayChieu"].HeaderText = "Ngày chiếu";
                    dataGridView.Columns["PhanTramGiamGia"].HeaderText = "Giảm giá";
                    FitSize(dataGridView);
                }
            }
        }

        private void FitSize(DataGridView gv)
        {
            Size fitSize = new Size();

            // get fit height
            fitSize.Height = gv.ColumnHeadersVisible ? gv.ColumnHeadersHeight : 0;
            fitSize.Height += gv.Rows[0].Height * (gv.Rows.Count);

            // get fit width
            fitSize.Width = gv.RowHeadersVisible ? gv.RowHeadersWidth : 0;
            fitSize.Width += (4*gv.Columns[0].Width);
            fitSize.Width += 5;

            gv.Size = fitSize;
        }
        private void buttonBack_Click(object sender, EventArgs e)
        {
            if (BackClickEvent != null)
            {
                BackClickEvent();
            }
        }
        public void CapNhatTenPhim(string s)
        {
            this.labeltenphim.Text = s;
        }

        private void buttonNext_Click(object sender, EventArgs e)
        {
            int index = dataGridView.CurrentRow.Index;
            if(index>=0)
            {
                if (NextClickEvent != null)
                {
                    NextClickEvent(DanhSachXuatChieu[index]);
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn lịch chiếu!!");
            }
        }

        private void buttonDatVeOnline_Click(object sender, EventArgs e)
        {
            int index = dataGridView.CurrentRow.Index;
            if (index >= 0)
            {
                if (XuLyDatVeOnline != null)
                {
                    XuLyDatVeOnline(DanhSachXuatChieu[index]);
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn lịch chiếu!!");
            }

        }
    }
}
